import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
import {Observable} from "rxjs/Observable"

@Injectable()
export class ServerHttpInterceptor implements HttpInterceptor {
    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

        let newRequest=null;
        let url=req.url;
        if(url.startsWith("http://")||url.startsWith("https://"))
        {
            return next.handle(req);
        }else
        {
            url=url.startsWith("/")?url:"/"+url;
            if(!url.startsWith("/server")) url="/server"+url;
            newRequest=req.clone({url:url});
            return next.handle(newRequest);
        }
    }
}